import player from "./Player";
const {ccclass, property} = cc._decorator;

@ccclass
export default class MenuCC extends cc.Component {

    @property({displayName: "player脚本所在节点", tooltip: "player脚本所在节点", type: player})
    player: player = null;

    @property({type: cc.Node, displayName: "战斗力面板", tooltip: "战斗力面板"})
    CC: cc.Node = null;



    @property({displayName: "显示等级的文字", tooltip: "显示等级的文字", type: cc.Label})
    LV_lb: cc.Label = null;

    @property({displayName: "显示攻击力的文字", tooltip: "显示攻击力的文字", type: cc.Label})
    ATK_lb: cc.Label = null;

    @property({displayName: "显示防御力的文字", tooltip: "显示防御力的文字", type: cc.Label})
    AC_lb: cc.Label = null;

    @property({displayName: "显示暴击率的文字", tooltip: "显示暴击率的文字", type: cc.Label})
    CRI_lb: cc.Label = null;

    @property({displayName: "显示战力的文字", tooltip: "显示战力的文字", type: cc.Label})
    ZL_lb: cc.Label = null;


    update () {
        // cc.log("原数", this.player.CRI, "保留小数后的数", this.player.CRI.toFixed(2));

        // 每帧更新文字显示的内容
        this.LV_lb.string = "等级：" + Math.floor(this.player.LV);
        this.ATK_lb.string = "攻击力：" + Math.floor(this.player.ATK);
        this.AC_lb.string = "防御力：" + Math.floor(this.player.AC);
        this.CRI_lb.string = "暴击率：" + (this.player.CRI.toFixed(2)) + "%";

        // 计算出综合战力
        let ZL = ((this.player.LV) * 100) + (this.player.full_HP * 0.65) + (this.player.full_MP * 0.2) + (this.player.ATK * 0.8) + (this.player.AC * 0.5) + (this.player.CRI * 100);
        // 在文字上显示
        this.ZL_lb.string = "综合战力：" + Math.floor(ZL);
    }



    // 关闭面板专用函数
    close_onbtn () {
        // 隐藏
        this.CC.active = false;
    }

    // 打开面板专用函数
    open_onbtn () {
        // 显示
        this.CC.active = true;
    }

}
